Scriplet API ================ ViCANdo can be extended with custom functionality, in the form of Scriptlets. Script components are written in JavaScript and a Scriptlet can be started on demand, or by a Trigger, configured to start a Scriptlet. You can run a script from Tools menu in ViCANdo: .. image:: _images/scriptletapi/run_a_script.jpg :scale: 70 % or .. image:: _images/scriptletapi/scriplet_add_new.jpg :scale: 70 % This section lists the Scriplet API functions you can use to make your own script. .. _ref-global-objects: Global objects ----------------------------- The global objects in ViCANdo project are: ================= ================================================== Name Description ================= ================================================== project Access project resources sources[] Array of sources avaliable in the project presenter[] Array of presenters available in the project scriptlet[] Array of Scriptlet available in the project trigger[] Array of triggers available in the project dbc[] Array of DBCs available in the project ================= ================================================== .. _ref-global-constants: ======================= Global constants ======================= constants:: var Idle = 0x00 // Project is idle var Preparing = 0x01 // waiting for enabled sources to be activated var Armed = 0x02 // All enabled sources are now active var Recording = 0x03 // Recording data from all enabled sources into a new session var Playing = 0x04 // Playing a previously recorded session var Pause = 0x05 // Playback or record has been paused var Rewind = 0x06 // Rewind will happen when a session has been played to its end point. It will start from the beginning on next play ======================= Global functions ======================= =========================================== ============================================ Prototype Description =========================================== ============================================ delay(time_in_ms) Wait for specified time in milli-seconds includeScript(relative_script_path) Include and parse another script file into this script context logMessage(string message) Log a text message to the project console window in ViCANdo =========================================== ============================================ .. js:function:: delay(time_in_ms) :param int time_in_ms: Time to wait in milli-seconds .. js:function:: includeScript(relative_script_path) :param string relative_script_path: Another script file to be included into this script context The **includeScript** function provides the possibility to include another script file into the current script context. Now, it's not pre-processor inclusion, the script will be evaluated in the current context, the variable will depend from where **includeScript** is called. A script will only be included once, if **includeScript** is called more than one time including the same script file, it will have no effect. For example: in hello.js file:: // hello.js project.log(“Hello World from hello.js”) IncludeScript(“hello_inc.js”) // Call function defined in hello_inc.js Hello() in hello_inc.js file:: //hello_inc.js project.log(“Hello from hello_inc.js”) // define a callable function this. Hello – function {} { project.log(“Hello from hello{} function”} } Project object ----------------------------- ================== Resources ================== All the resources/components inside the project can be accessed in JavaScript: ======================= ================================================================================ Name Description ======================= ================================================================================ project.sources[] Array of sources available in project. Also available as a :ref:`ref-global-objects`. project.presenter[] Array of presenters available in project. Also available as a :ref:`ref-global-objects`. project.scriptlet[] Array of Scriptlet available in project. Also available as a :ref:`ref-global-objects`. project.trigger[] Array of triggers available in project. Also available as a :ref:`ref-global-objects`. project.dbc[] Array of DBC’s available in project. Also available as a :ref:`ref-global-objects`. ======================= ================================================================================ Every component in the project tree (Source, Presenters, Scriptlets, etc.) can be named with an **Object name**. This is done through the **Component Properties** pane in ViCANdo. A component can be accessed from JavaScript by its object name, via the project object: **project.**. Example using a CAN Source where its **Object name** is set to **main_can_source**:: // Send an extended CAN frame project.main_can_source.send(0x2500,new Array(10,20,30,40,50,60,70,80)} ================== Methods ================== All the methods of the ViCANdo project can be accessed, for example: project.log("This is a log"). Below is a list of all the methods. Log a text message to the project console (just a short alias to logMessage function): .. js:function:: log(message) :param string message: The text message to be logged .. js:function:: currentState() :returns: Return the current state, may be :ref:`ref-global-constants` Wait for State Change within a specified time period: .. js:function:: waitForStateChange(timeout_in_ms) :throws: timeout exception if no state change happen in specified timeout .. js:function:: registerStateChangeCallback(callback) :param callback: The function callback that will be invoked when the project state has changed This function registered will only be called when the script is running. After script has finished, no more callbacks are received. The callback function has two parameters: **previous_state** and **new_state** that will be some of the :ref:`ref-global-constants` Example on how to use the registerStateChangeCallback function:: project.registerStateChangeCallback{function(previous_state,new_state) { project.log(“Previous state” + previous_state) project.log(“New state” + new_state) }) project.log(“waiting for state change”) project.waitForStatechange(5000) Activate all enabled sources, next state will be Armed: .. js:function:: activate() Start recording. Can only be done in Armed state: .. js:function:: startRecord() Stop all activity and go to Idle state: .. js:function:: stop() Clear the ViCANdo text console: .. js:function:: clearConsole() Store a value within the project: .. js:function:: storeValue(String key, value, persistent) :param string key: The index to the vlaue stored :param value: The value to be stored. Only string values can be permanently stored. :param bool persistent: If persistent is true, the value will be permanently stored within the project. Otherwise, the value will be permanent until the project is closed or the script engine is restarted. Remove a stored value: .. js:function:: removeValue(string key) :param string key: The index to the vlaue to be removed Retrieve a stored value from the list: .. js:function:: value(string key) :param string key: The index to the vlaue in the stored value list :returns: The value retrieved Remove all stored values: .. js:function:: clearStoredValues() QML Presenter object ----------------------------- Set a property with given value in the QML component: .. js:function:: setProperty(string property_name, object value) :param string property_name: The name of the property :param object value: The value to be set Get the value for a specified property in the QML components: .. js:function:: property(string property_name) :param string property_name: The name of the property :returns: The value of the property Timer object ----------------------------- .. js:class:: Timer =========================================== ============================================ Prototype Description =========================================== ============================================ integer elapsedInMs() Elapsed time in milli-seconds since the timer was started integer elapsedInUs() Elapsed time in micro-seconds since the timer was started restart() Restart the timer =========================================== ============================================ .. js:function:: elapsedInMs() :returns: Elapsed time in milli-seconds .. js:function:: elapsedInUs() :returns: Elapsed time in micro-seconds .. js:function:: restart() Example:: var timer1 = Timer() // do something... var elapsed_time_in_us = timer1.elapsedInUs() var elapsed_time_in_ms = timer1.elapsedInMs() ======================= Timer with a callback ======================= =========================================== ============================================ Prototype Description =========================================== ============================================ Timer() Create a new timer with a given JavaScript function that will be invoked on timeout start(timeout_in_ms) Start timer with specified timeout in milli-seconds stop() Stop the timer singleshot = true/false Single shot property, set to true and timer will only expire 1 time after start() =========================================== ============================================ .. js:class:: Timer(JavaScript_function) :param string JavaScript_function: The JavaScript function that will be invoked on timeout .. js:function:: start(timeout_in_ms) :param timeout_in_ms: Timeout in milli-seconds .. js:function:: stop() .. note:: All timers will be automatically stopped after script has finished Example using a periodic timer:: var counter = 0 var t1 = new Timer(function{}{ project.log(“Timer callback” + counter) counter ++ }) T1.start(1000) Example using a ingle-shot timer:: var t1 = new Timer(function{} { project.log (“Timer has expired”) }) T1.singleshot = true T1.start(1000) System functions ----------------------------- Provides a collection of system functions. Start a new program with the arguments given in argument list and wait for the process to finish. If the script engine is stopped before the program has finished the process will be brutally terminated. The return value from this function contains the process exit code the standard and error output as a string in a array as {,,< Standard-error>}: .. js:function:: system.executeProgram(string program, argument_list) :param string program: The program to be executed :param argument_list: The arguments when executing with the program :returns: array of status: [,,< Standard-error>] Start a new process program with the arguments given in arguments list and spawn it in the background. The return result is the PID of the process: .. js:function:: system.executeProgramDetached(string program, argument_list) :param string program: The program to be executed :param argument_list: The arguments when executing with the program :returns: PID of the process List all available text codecs by name. Return an array of string objects: .. js:function:: system.availableTextCodecs() File System functions ----------------------------- Provides a collection of functions for file I/O and basic file-system manipulation. All functions are provides by the fs object: ====================== fs object ====================== Remove/delete a give path on file-system: .. js:function:: fs.unlink(string path) :param string path: Path to be deleted Rename file specified by old_path to new_path: .. js:function:: fs.rename(string old_path, string new_path) :param string old_path: The old path of the file :param string new_path: The new path of the file Return true if the specified path exists on the file-system: .. js:function:: fs.fileExists(string path) :param string path: The path to be checked :returns: true if path exists, false if path doesn't exist Return true if the specified path is a directory: .. js:function:: fs.openDirectory(string path) :param string path: The path given :returns: true if the path is a directory, false otherwise Open a file. Mode can be “r’ for read only.”w” only write, ”rw” for read and write, “a” for append stream object: .. js:function:: fs.openFile(string path, string mode) :param string path: The path of the file :param string mode: The open file mode. "r" for read only. "w" for wirte only. "rw" for read and wirte. "a" for append stream object. :returns: The file :ref:`ref-stream-object` Close an opened stream: .. js:function:: fs.close(stream stream) :param stream stream: The stream to be closed Returns the absolute path of the process current working directory: .. js:function:: fs.currentDirectory() :returns: The path of the process current wokring directory Returns the absolute path of the user’s home directory. This will differ depending on operating system: .. js:function:: fs.homeDirectory() :returns: The path of the user's home directory Returns the absolute path of the operating system’s temporary directory: .. js:function:: fs.tempDirectory() :returns: The path of the operating system's temporary directory Returns directory separator used on the target system, “I “under Unix (including Mac OS X) and “\” under Windows: .. js:function:: fs.separator() :returns: The separator: “I “under Unix (including Mac OS X) and “\” under Windows Change the current directory to path: .. js:function:: fs.chdir(string path) :param string path: Path to be changed to Create directory path: .. js:function:: fs.mkdir(string path) :param string path: Path to be created. The path should be relative to currentDirectory(). Remove a directory: .. js:function:: fs.rmdir(string path) :param string path: Path to be removed, must be a directory and it is relative to currentDirectory(). Returns a list of files in the specified path: .. js:function:: fs.list (string path) :param string path: The specified path :returns: a array of files in the specified path. e.g. ["file1", "file2", "file3"] Returns a list of files and directories in the specified path: .. js:function:: fs.listFiles(string path) :param string path: The specified path :returns: a array of files and directories in the specified path. Return a :ref:`ref-fileinfo-object` for the given path. The :ref:`ref-fileinfo-object` provides system independent file information: .. js:function:: fs.fileInfo(string path) :param string path: The given path :returns: a :ref:`ref-fileinfo-object` .. _ref-stream-object: ====================== stream object ====================== Write a line to stream, LF is added to the end: .. js:function:: stream.writeLine(string string) :param string string: The string to be written Read a line from the stream. If not a complete line is read from in timeout_in_ms millis-seconds, execution is aborted with an exception: .. js:function:: stream.readLine(timeout_in_ms) :param timeout_in_ms: The timeout time in milli-seconds :returns: The line was read :throws exception: If not a complete line is read from when reach the timeout_in_ms millis-seconds, execution is aborted with an exception Flushes any buffered data to the stream: .. js:function:: stream.flush() Return true if at end of file: .. js:function:: stream.eof() Set the text codec to used when read and writing text from this stream. Use system.availableTextCodecs() list available text codecs: .. js:function:: setEncoding(string codec_name) :param string codec_name: The name of the codec. .. _ref-fileinfo-object: ====================== fileinfo object ====================== A fileinfo object contains below properties: ================= ================================================== Property Description ================= ================================================== path Absolute path including the file name created The date and time when the file was created lastModified The date and time when the file was last modified lastRead The date and time when the file was last read (accessed) size The size of the file in bytes owner The Owner of the file. On systems where files do not have owners or if an error occurs. It will contain an empty string group The group of the file. On windows on systems where files do not have owners or if an error occurs it will contain an empty string directory Set to true if this object points to a directory or to a symbolic link to a directory. Otherwise set to false executable Set to true if the user can read the file. Otherwise set to false hidden Set to true if this is a ‘hidden’ file. Otherwise set to false readable Set to true if the user can read the file. Otherwise set to false writable Set to true if the user can write to the file. otherwise set to false symlink Set to true if this object points to a symbolic link(or to a shortcut on Windows). Otherwise set to false ================= ================================================== Example creating a text file and writing some lines:: var out = fs.openFile("/tmp/test.txt","w") out.writeLine("Test line 1") out.writeLine("Test line 2") out.writeLine("Test line 3") out.writeLine("Test line 4") fs.close(out) Example reading some lines from a text file:: var f = fs.openFile("/tmp/test.txt","r") var line_no = 1; while (!f.eof()) { project.logMessage("line " + line_no + " " + f.readLine()); line_no ++; } fs.close(f) CAN Source object ----------------------------- =========== Constants =========== .. js:data:: can.flag.Rtr = 0x00001 .. js:data:: can.flag.Standard = 0x00002 .. js:data:: can.flag.Extended = 0x00004 .. js:data:: can.flag.Wakeup = 0x00008 .. js:data:: can.flag.NError = 0x00010 .. js:data:: can.flag.ErrorFrame = 0x00020 .. js:data:: can.flag.TxMsgAcknowledge = 0x00040 .. js:data:: can.flag.TxMsgRequest = 0x00080 .. js:data:: can.flag.ErrorMask = 0x0ff00 .. js:data:: can.flag.ErrorHWOverrun = 0x00200 .. js:data:: can.flag.ErrorSWOverrun = 0x00400 .. js:data:: can.flag.ErrorStuff = 0x00800 .. js:data:: can.flag.ErrorForm = 0x01000 .. js:data:: can.flag.ErrorCRC = 0x02000 .. js:data:: can.flag.ErrorBIT0 = 0x04000 .. js:data:: can.flag.ErrorBIT1 = 0x08000 .. js:data:: can.flag.Statistic = 0x10000 ============= Methods ============= Send a CAN frame, extended ID is default: .. js:function:: send(uint id, byte[] data) :param uint id: The identifier of the CAN frame :param byte[] data: Array of CAN frame data. The format is: [b0, b1, b2, b3, b4, b5, b6, b7] Send an extended CAN frame: .. js:function:: sendExtended(int id, byte[] data) :param int id: The identifier of the CAN frame :param byte[] data: Array of CAN frame data. The format is: [b0, b1, b2, b3, b4, b5, b6, b7] Send a standard CAN frame: .. js:function:: sendStandard(int id, byte[] data) :param int id: The identifier of the CAN frame :param byte[] data: Array of CAN frame data. The format is: [b0, b1, b2, b3, b4, b5, b6, b7] Send a remote CAN frame, default is extended: .. js:function:: sendRemote(int id, byte[] data) :param int id: The identifier of the CAN frame :param byte[] data: Array of CAN frame data. The format is: [b0, b1, b2, b3, b4, b5, b6, b7] Send a standard remote CAN frame: .. js:function:: sendStandardRemote(int id, byte[] data) :param int id: The identifier of the CAN frame :param byte[] data: Array of CAN frame data. The format is: [b0, b1, b2, b3, b4, b5, b6, b7] Send an extended remote CAN frame: .. js:function:: sendExtendedRemote(int id, byte[] data) :param int id: The identifier of the CAN frame :param byte[] data: Array of CAN frame data. The format is: [b0, b1, b2, b3, b4, b5, b6, b7] Receive a CAN frame, if nothing is received in timeout_in_ms script execution is aborted with an exception: .. js:function:: receive(timeout_in_ms) :param timeout_in_ms: Time out time in milli-seconds :return: CAN frame array in the form of: [ID, Flags, B0, B1, B2, B3, B4, B5, B6, B7] :throws exception: If nothing is received in specified timeout time Returns true if source is attached to virtual CAN interface: .. js:function:: isVirtual() :returns: true if the source is virtual CAN interface. Otherwise false. ======================= Properties ======================= ================= ================= ======================= Property Type Description ================= ================= ======================= deviceList string-array List of current available CAN interfaces device Integer The current device index deviceName string The name of the current CAN interface ================= ================= ======================= Example using the a CAN source object. *source[0]* is a CAN source:: // Send an extended CAN 29bit frame source[0].send(0x2500,new Array(10,20,30,40,50,60,70,80)); // Send a standard CAN 11bit frame source[0].sendStandard(0x100,new Array(10,20,30,40,50,60,70,80)); Example Recieving a CAN frame:: var can_frame; while (true) { can_frame = source[0].receive(5000) project.logMessage("Received CAN frame: " + can_frame) } This example is waiting to recieve a CAN frame for 5000 ms. If the CAN frame is not recieved on time, ViCANdo console window will print "Error: Timed out waiting for CAN frame" In ViCANdo console window, the recieved frames are displayed like this: .. image:: _images/scriptletapi/receive_can_frame.jpg :scale: 70 % The message in the above console window (Test with recieve Script) Received CAN frame: 1793,2,4,103,4,103,3,48,5,119 means: (project name) Recieved CAN frame: ID, Flags, B0, B1, B2, B3, B4, B5, B6, B7 J1939 Source object ----------------------------- Send J1939 message addressed to a node in the network: .. js:function:: send(sa,da,priority,pgn,byte[] data) :param sa: Source address :param da: Destination address :param priority: The priority of the message :param pgn: The PGN number :param byte[] data: The data of the message Send a broadcast J1939 message: .. js:function:: sendBAM((sa,da,priority,pgn,byte[] data) :param sa: Source address :param da: Destination address :param priority: The priority of the message :param pgn: The PGN number :param byte[] data: The data of the message Receive a J1939 message, if nothing is received in timeout_in_ms, script execution is aborted with an exception: .. js:function:: receive(timeout_in_ms) :param timeout_in_ms: Timeout time in milli-seconds :returns: Array contains J1939 message information. The format is: [sa, da, priority, pgn flags, b0, b1, b2, b3, b4, b5...] ISO15765 Source object ----------------------------- ================================== Basic Contepts and abbreviations ================================== **PCI** Protocol Control Information. May be single-Frame, First-Frame, Flow-Control or Consecutive-Frame. Find more details in the ISO15765 specification. **Data** The payload of an ISO15765 message. Find more details in the ISO15765 specification. **M Type** May be diagnostics or remote diagnostics. The parameter Mtype shall be used to identify the type and range of address information parameters included in a service call. This part of ISO 15765 specifies a range of two values for this parameter. The intention is that users of the documents can extended the range of values by specifying other types and combination of address information parameter to be used with the network layer protocol specified in this document. For each such new range of address information a new value for the Mtype parameter shall be specified to identify the new address information. - If Mtype = diagnostics then the address information AI shall consist of the parameters SA,TA and TAtype - If Mtype = remote diagnostics then the parameters AI shall consist of the parameters SA, TA, TAtype and AE **AI** These parameters refers to addressing information. As a whole, the AI parameters are used to identify the source address (SA), target address (TA) of message senders and recipients as well as the communication model for the message (TAType) and the optional address extension (AE). **SA** Network Source Address, 1 byte unsigned integer value range 00-FF hex. The SA parameter shall be used to encode the sending network layers protocol entity. **TA** Network Target Address, 1 byte unsigned integer value, range 00-FF hex. The TA parameter shall be used to encode the receiving network layer protocol entity. **TAType** Network Target Address type physical or functional. Physical addressing (1-1 communication) shall be supported. **AE** Network Address Extension, 1 byte unsigned integer value, range 00-FF Hex. The AE parameter is used to extend the available address range for large networks, and tonencode both sending and receiving network layers entities of subnets other than the local network where the communication takes place. AE is only part of the addressing information if Mtype is set to remote diagnostics. ================================== Addressing modes ================================== **Normal addressing** For each combination of SA, TA, TAtype and Mtype, a unique CAN identifier is assigned. PCI and Data is placed within the CAN frame data. For this mode an addressing map must be defined, see *.setAddressMap (address_map)* **Fixed addresssing** Normal fixed addressing is a sub format of normal addressing where the mapping of the address information into the CAN identifier is further defined. In the general case of normal addressing, described above, the correspondence between AI and the CAN identifier is left open. For normal fixed addressing, only 29 bit CAN identifiers are allowed. **Extended addressing** For each combination of SA, TAtype and Mtype, a unique CAN identifier is assigned. TA is placed in the first data byte of the CAN frame data. PCI and Data is placed in the remaining bytes of the CAN frame data field. For this mode an addressing map must be defined, see *.setAddressMap (address_map)* **Mixed addressing** Mixed addressing is the addressing format to be used if Mtype is set to remote diagnostics. **29 bit CAN identifier** The address information(AI) is in the 29 bit CAN identifier, and the first CAN frame data byte shall be the AE. **11 bit CAN identifier** For each combination of SA, TA and TAtype a unique CAN identifier is assigned. AE is placed in the first data byte of the CAN frame data. PCI and Data is placed in the remaining bytes of the CAN frame data field. For this mode an addressing map must be defined, see *.setAddressMap (address_map)* ================================== Constants ================================== .. js:data:: tp.iso15765.NormalAddressMode = 0x0 .. js:data:: tp.iso15765.ExtendedAddressMode = 0x1 .. js:data:: tp.iso15765.FixedAddressMode = 0x2 .. js:data:: tp.iso15765.MixedAddressMode = 0x3 .. js:data:: tp.iso15765.Physical = 0x0 .. js:data:: tp.iso15765.Functional = 0x1 .. js:data:: tp.iso15765.ExtAddrFlag = 0x20000 .. js:data:: tp.iso15765.UnknownTypeFlag = 0x40000 ================================== Methods ================================== Set the address map, used for Normal, Extended and Mixed addressing (using 11-bit CAN identifiers), see example below. .. js:function:: setAddressMap(address_map) :param address_map: The address map to be set. Send a ISO15765 message, to from SA, addressed to TA: .. js:function:: send(sa,ta,ta_type,id, byte[] data) :param sa: SA :param ta: TA :param ta_type: TAType :param id: identifier :param byte[] data: Data of the ISO15765 message Send a ISO15765 message specifying the request and response CAN id. NOTE: this function can only be used when in **Normal addressing** mode. When sending *functional* or single frame messages *can_response_id* is allowed to be set to *null*: .. js:function:: sendNormalRaw(can_request_id, can_response_id, byte[] data) :param can_request_id: Request CAN identifier :param can_response_id: Response CAN identifier :param byte[] data: Data of the ISO15765 message Receive a ISO15765 message, if nothing is received in *timeout_in_ms* script execution is aborted with an exception. On successful receive of a message an array is returned: .. js:function:: receive(timeout_in_ms) :param tiemout_in_ms: Timeout time in milli-seconds :returns: For MixedAddressMode, array format is: [,,,,,,]. For other mode, array format is: [,,,,,] :throws exception: If nothing is received in specified timeout time, script exception is aborted. ================================== Defining an address map ================================== For Normal, Extended, and Mixed address mode (with 11bit CAN identifiers) an address map must be defined. A unique CAN identifier is defined for each combination of SA, TA and TAType. Note that for extended address mode only SA and TAType is used. Example defining an address map having 3 nodes in the network, with addresses 1, 2 and 5:: var address_map = [ { id:0x242, sa:5, ta:1,ta_type:tp.iso15765.Physical }, { id:0x243, sa:5, ta:2, ta_type:tp.iso15765.Physical }, { id:0x542, sa:1, ta:2, ta_type:tp.iso15765.Physical }, { id:0x543, sa:2, ta:1, ta_type:tp.iso15765.Physical }, { id:0x643, sa:1, ta:5, ta_type:tp.iso15765.Physical }, { id:0x843, sa:2, ta:5, ta_type:tp.iso15765.Physical } ] project.iso_source.setAddressMap(address_map) Example sending a Single-Frame:: // SA 1 TA 2 TAType Physical iso_source.send(1,2, tp.iso15765.Physical, [22,23,24,25,26,27]); Example sending a Multi-Frame:: var packet = []; for ( i = 0; i < 33; ++i ) { packet.push(i) } // SA 2 TA 5 TAType Physical iso_source.send(2,5,tp.iso15765.Physical, packet); LIN Source object ----------------------------- ========== Constants ========== .. js:data:: lin.flag.ParityError = 0x00001 // Rx: parity error (the identifier) .. js:data:: lin.flag.ChecksumError = 0x00002 // Rx: checksum error .. js:data:: lin.flag.NoData = 0x00004 // Rx: header only .. js:data:: lin.flag.BitError = 0x00008 // Tx: transmitted 1, got 0 or vice versa .. js:data:: lin.flag.TxSlaveResponse = 0x00010 // Rx: echo of a slave response we transmitted .. js:data:: lin.flag.ClassicChecksum = 0x00020 // Rx or Tx .. js:data:: lin.flag.TxMsgAcknowledge = 0x00040 // Tx message acknowledge .. js:data:: lin.flag.TxMsgRequest = 0x00080 // Tx message request .. js:data:: lin.flag.ErrorHWOverrun = 0x00200 // Rx: LIN interface overrun .. js:data:: lin.flag.ErrorSWOverrun = 0x00400 // Rx: receive queue overrun .. js:data:: lin.flag.SynchError = 0x00800 // Synch error .. js:data:: lin.flag.WakeUp = 0x01000 // A wake up frame was received ========== Methods ========== Send data on the LIN bus: .. js:function:: send(uint id, byte[] data) :param uint id: identifier :param byte[] data: array of data to be sent. The format is: [b0, b1, b2, b3, b4, b5, b6, b7] Receive data on the LIN bus, if nothing is received in timeout_in_ms script execution is aborted with an exception: .. js:function:: receive(timeout_in_ms) :param timeout_in_ms: Timeout time in milli-seconds :returns: array of received data. The format is: [id, flags, [b0,b1,b2,b3,b4,b5,b6.b7] ] Set or update a message response data for a specified ID, only for slave: .. js:function:: setSlaveResponse(uint id, byte[] data) :param uint id: identifier :param byte[] data: array of data. The format is: [b0, b1, b2, b3, b4, b5, b6, b7] Clear a message response, only for slave: .. js:function:: clearslaveResponse(uint id) :param uint id: identifier Clear all message response, only for slave: .. js:function:: clearslaveResponse() For master node, request a response from a slave: .. js:function:: sendMasterRequest(uint id) :param uint id: identifier Send a wake-up frame: .. js:function:: sendWakeUp() LIN master and slave example:: var master = project.master_lin_channel var slave = project.slave_lin_channel slave.setSlaveResponse(10, [1,2,3,4,5,6,7,8]) slave.setSlaveResponse(11, [10,20,30,40,50,60,70,80]) slave.setSlaveResponse(12, [11,21,31,41,51,61,71,81]) slave.setSlaveResponse(13, [12,22,32,42,52,62,72,82]) slave.setSlaveResponse(14, [13,23,33,43,53,63,73,83]) slave.setSlaveResponse(15, [14,24,34,44,54,64,74,84]) project.log("Send master request") for ( var i = 10; i <=15; ++i ) { master.sendMasterRequest(i) var response do { response = slave.receive(100) } while( response[0] != i) project.log("Slave response: " + response) }